#!/bin/bash

# 批量替换 xlayer.service.ts 中的所有 LAUNCHPAD_ADDRESS 默认值

cd /Users/zyu/leo/ignite-fun/backend/src/services

# 备份原文件
cp xlayer.service.ts xlayer.service.ts.backup

# 使用 sed 进行批量替换
# 替换所有的 process.env.XLAYER_LAUNCHPAD_ADDRESS || '0x...' 为 this.LAUNCHPAD_ADDRESS
sed -i '' \
  -e 's/process\.env\.XLAYER_LAUNCHPAD_ADDRESS ||[[:space:]]*'"'"'0x[^'"'"']*'"'"'/this.LAUNCHPAD_ADDRESS/g' \
  -e 's/process\.env\.XLAYER_LAUNCHPAD_ADDRESS[[:space:]]*||[[:space:]]*'"'"'0x[^'"'"']*'"'"'/this.LAUNCHPAD_ADDRESS/g' \
  -e 's/(process\.env\.XLAYER_LAUNCHPAD_ADDRESS || '"'"'0x[^'"'"']*'"'"')/this.LAUNCHPAD_ADDRESS/g' \
  xlayer.service.ts

echo "替换完成！检查结果..."
grep -n "process.env.XLAYER_LAUNCHPAD_ADDRESS ||" xlayer.service.ts | wc -l
echo "剩余未替换的数量: $(grep -n "process.env.XLAYER_LAUNCHPAD_ADDRESS ||" xlayer.service.ts | wc -l)"
